var express = require('express');
var router = express.Router();

var formidable = require('formidable');

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.get('/portrait', function(req, res) {
  res.render('portrait');
});

router.post('/portrait', function(req, res) {
  // 创建 form 对象
  const form = new formidable.IncomingForm({ 
    multiples: true, 
    uploadDir: __dirname + '/../public/images', 
    keepExtensions: true 
  })
    //解析客户端传过来的FormData对象
    form.parse(req, (err, fields, files) => {
      console.log(files)  
      console.log(fields)  
      res.send('ok');
  });
});

module.exports = router;
